/**
 * @Author 12629
 * @Description：
 */
class Student {
    public int age;

    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
public class Test {

    public static void main21(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 1_0000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);


        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }


    public static void main(String[] args) {
        String s = "hello";
        s += " world";
        System.out.println(s);  // 输出：hello world
        // 【但是这个是一个全新的对象，不是在原来的hello这个内存上拼接的】
    }

    public static void main20(String[] args) {
        final char[] value = new char[] {'a','b','c'};
        // value = new char[10];//value的指向不能发生改变

        value [0] = 'p';
        System.out.println("fASDFA");
    }

    public static void main19(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String s1 = new String(ch);
//        s1.intern();

        String s2 = "abc";

        s1.intern();

        System.out.println(s1 == s2);

    }


    public static void main18(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        System.out.println(s1 == s2);

        String s3 = new String("hello");
        System.out.println(s3 == s1);

    }

    public static void main17(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        String s3 = new String("hello");
        String s4 = new String("hello");
        System.out.println(s1 == s2);    // true
        System.out.println(s1 == s3);    // false
        System.out.println(s3 == s4);    // false
    }

    public static void main16(String[] args) {
        String str = "abcdef";
        String ret = str.substring(1,4);//[1,4)
        System.out.println(ret);
        System.out.println("=============");
        String s = "    abdc dfefe fdfa       ";
        System.out.println(s.trim());//当前字符串的左右的空格去掉
        System.out.println(s);

    }

    //
    public static void main15(String[] args) {
        String str = "name=zhangsan&age=18" ;
        String[] ret = str.split("&");
        for (String s : ret) {
            //s[0] => name=zhangsan
            //s[1] => age=18
            String[] ss = s.split("=");
            for (String x : ss) {
                System.out.println(x);
            }
        }
    }

    public static void main14(String[] args) {
        String str = "105Java zhang&san";
        String[] ret = str.split(" |&");
        for (String s : ret) {
            System.out.println(s);
        }
    }

    public static void main13(String[] args) {
        String str = "192\\168\\1\\1";
        String[] ret = str.split("\\\\");
        for (String s : ret) {
            System.out.println(s);
        }
    }

    public static void main12(String[] args) {
        String str = "192.168.1.1";
        String[] ret = str.split("\\.");
        for (String s : ret) {
            System.out.println(s);
        }
    }

    public static void main11(String[] args) {
        String s1 = "hello biter welcome to bit";
        String[] ret = s1.split(" ",13);
        for (String s : ret) {
            System.out.println(s);
        }
    }

    public static void main10(String[] args) {
        String s1 = "ababcabcdabcde";
        /*String ret = s1.replace('a','T');
        System.out.println(ret);
*/
        /*String ret = s1.replace("ab","qq");
        System.out.println(ret);*/

        /*String ret = s1.replaceAll("ab","qq");
        System.out.println(ret);*/
        String ret = s1.replaceFirst("ab","qquuuuu");
        System.out.println(ret);

        System.out.println("s1->  "+s1);
    }

    public static void main9(String[] args) {
        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);
    }

    public static void main8(String[] args) {
        String s1 = "hello";
        char[] chars = s1.toCharArray();
        for (char x : chars) {
            System.out.println(x);
        }
        System.out.println(s1);
    }

    public static void main7(String[] args) {
        String s1 = "hello";
        String ret = s1.toUpperCase();
        System.out.println(ret);
        System.out.println("s1-> " + s1);
        String s2 = "HELLO";
        ret = s2.toLowerCase();
        System.out.println(ret);
        System.out.println("fdsafa-> "+s2);
    }

    public static void main6(String[] args) {
        //把其他的数据类型 变成字符串
        String s = String.valueOf(123);
        String s2 = String.valueOf(12.5);
        System.out.println(s);
        System.out.println(s2);

        String s4 = String.valueOf(new Student(18));
        System.out.println(s4);

        int a = Integer.valueOf("64");//6*8^1 + 4*8^0 = 52
        System.out.println(a);
        int a2 = Integer.parseInt("100");
        System.out.println(a2);
    }

    public static void main5(String[] args) {
        String s1 = "ababcabcde";
        int index = s1.lastIndexOf('a',4);
        System.out.println(index);
    }

    public static void main4(String[] args) {
        String s1 = "ababcabcdabcde";
        for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);
            System.out.print(ch+" ");
        }
        System.out.println("===============");
        int index = s1.indexOf('l',3);//查找第一次出现的字符
        System.out.println(index);
        System.out.println("===============");
        index = s1.indexOf("abc");//KMP算法：
        System.out.println(index);
    }
    public static void main3(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        System.out.println(s1.compareTo(s2));
        //忽略大小写进行比较大小
        System.out.println(s1.compareToIgnoreCase(s2));

        System.out.println("============");
        System.out.println(s1.equals(s2));
        //忽略大小写比较是否相同
        System.out.println(s1.equalsIgnoreCase(s2));
    }


    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");

        System.out.println(s1 == s2);   // false
        System.out.println(s1.equals(s2));


        System.out.println(s2 == s3);   // false
        System.out.println(s2.equals(s3)); // false

        System.out.println(s1.compareTo(s2));


    }
    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("abcd");
        char[] chars = {'a','b','c'};
        String str3 = new String(chars);

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);

        System.out.println(str1.length());

        int[] array = {1,2,3};
        System.out.println(array.length);
    }
}
